<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : message.php   FILE_PATH : D:\webroot\mulitishop\store\message.php
 * ....商铺留言显示
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Sat Sep 15 13:36:23 CST 2007
 */

require_once("../global.inc.php");

class StoreMessage extends CommonFrameWork{
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	/**
	 * 商铺留言对象
	 *
	 * @var obj
	 */
	var $obj_shopmessage;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	/**
	 * 网站提醒对象
	 *
	 * @var obj
	 */
	var $obj_remind;
	
	function main(){
		$this->ifStore();
		//echo $this->shop_id;
		/**
		 * 创建商铺分类对象
		 */
		if (!is_object($this->obj_shopmessage)){
			require_once("shopmessage.class.php");
			$this->obj_shopmessage = new ShopMessageClass();
		}
		
		/**
		 * 创建分页对象
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("store");

		/**
		 * 语言包
		 */
		$this->getlang("shop");
		
		$this->storeBaseInfo();    //店铺基本信息

		switch($this->_input['action']){
			case "new":
				$this->_addMessage();
				break;
			case "save":
				$this->_saveAddMessage();
				break;
			default:
				$this->_getMessageList();
		}
	}

	/**
	 * 留言列表
	 */
	function _getMessageList(){
		$this->obj_page->pagebarnum(20);    //每页20条记录
		
		$message_array = $this->obj_shopmessage->getMessage($this->obj_page,$this->shop_id,true);     //得到留言列表
		$pagelist = $this->obj_page->show(1);    //分页显示
		$this->output('shop_message_array',$message_array);    //输出商铺留言列表
		$this->output('shop_message_pagelist',$pagelist);      //输出商铺留言分页
		$this->showpage("store_message.list");
	}
	
	/**
	 * 发表留言
	 *
	 */
	function _addMessage(){
		$this->showpage('store_message.add');
	}
	
	/**
	 * 保存留言
	 *
	 */
	function _saveAddMessage(){
		/**
		 * 检验输入信息
		 */
		
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtMessage"],"require"=>"true","message"=>"请填写留言内容"),
		array("input"=>strtoupper($this->_input['code']),"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>strtoupper($_SESSION['seccode']),"message"=>"您输入的验证码不对")
		); 
		//echo $_SESSION['seccode'] . "|" . $this->_input['code'];exit;
		/**
		 * 检验的错误信息
		 */
		$error = $this->objvalidate->validate();
		if ($error != ""){
			echo $error;
		}else{
			/**
			 * 网站提醒操作
			 */
			if (!is_object($this->obj_remind)){
				require_once('remind.class.php');
				$this->obj_remind = new RemindClass();
			}
			/**
			 * 创建会员对象
			 */
			if (!is_object($this->obj_member)){
				require_once("member.class.php");
				$this->obj_member = new MemberClass();
			}
			$condition['id'] = $this->_input['userid'];
			$member_array = $this->obj_member->getMemberInfo($condition);
	
			$value_array = array();
			$value_array['username'] = $member_array['login_name'];
			$this->obj_remind->setMessageOrMail('sale_message_shop','message_shop',$value_array,$member_array['login_name'],$this->_configinfo);

			$this->_input['MemberName'] = $_SESSION['s_login']['name'];
			$this->_input['hideShopID'] = $this->shop_id;
			$this->obj_shopmessage->addMessage($this->_input);   //将留言内容存放到数据库中
			$this->redirectPath("succ","store/message.php?userid=" . $this->_input['userid'],"您已经成功给店家留言");
		}
	}

}
$message = new StoreMessage();
$message->main();
unset($message);
?>